// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "ExternalRpcRegistrationComponent.h"
#include "Serialization/JsonSerializer.h"

#include "Dom/JsonObject.h"
#include "LyraGameplayRpcRegistrationComponent.generated.h"

#define UE_API LYRAGAME_API

UCLASS(MinimalAPI)
class ULyraGameplayRpcRegistrationComponent : public UExternalRpcRegistrationComponent
{
	GENERATED_BODY()
protected:
	static UE_API ULyraGameplayRpcRegistrationComponent* ObjectInstance; // 单例对象实例

public:
	/**
	 * 获取 RPC 注册组件的单例实例
	 */
	static UE_API ULyraGameplayRpcRegistrationComponent* GetInstance();

#if WITH_RPC_REGISTRY
	/**
	 * 从请求体数据中解析并获取 JSON 对象
	 */
	UE_API TSharedPtr<FJsonObject> GetJsonObjectFromRequestBody(TArray<uint8> InRequestBody);

	/**
	 * 注销所有已注册的 HTTP 回调
	 */
	UE_API virtual void DeregisterHttpCallbacks() override;

	/**
	 * 注册始终启用的 HTTP 回调（无论游戏处于何种状态）
	 */
	UE_API virtual void RegisterAlwaysOnHttpCallbacks() override;
	/**
	 * 处理执行作弊命令的 HTTP 请求
	 */
	UE_API bool HttpExecuteCheatCommand(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);

	/**
	 * 注册仅在前端（如主菜单）启用的 HTTP 回调
	 */
	UE_API virtual void RegisterFrontendHttpCallbacks();
	//bool HttpSetMatchType(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);

	/**
	 * 注册仅在比赛中启用的 HTTP 回调
	 */
	UE_API virtual void RegisterInMatchHttpCallbacks();
	/**
	 * 处理触发一次射击的 HTTP 请求
	 */
	UE_API bool HttpFireOnceCommand(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);

	/**
	 * 处理获取玩家状态（如生命值、物品栏）的 HTTP 请求
	 */
	UE_API bool HttpGetPlayerVitalsCommand(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);

#endif

};

#undef UE_API